export default class Push {
	constructor(args) {
		this.pushId = null;
		this.timer = null;
		this.fn = args.fn;
	}

	async cycle() {
		if(this.timer){
			clearTimeout(this.timer);
			this.timer = null;
		}

		let clientid =  await this.getClientid();

		if (clientid) {
			this.pushId = clientid;

			this.fn(this.pushId);
		} else {
			this.timer = setTimeout(this.cycle.bind(this), 1000);
		}
	}

	getPushId() {}

	getClientid() {
		return new Promise( async (resolve, reject) => {
			plus.push.getClientInfoAsync((info)=> {
				let cid = info.clientid; //客户端标识

				resolve(cid);
			}, (e)=> {

			})
		})
	}
}
